import {
  LOGIN,WXLOGIN,WXBINDING,WXBINDINGCASE,
  WXUNBINDING,ROUTES,USER,
  ADDUSER,UPDATEUSER,
  AUTHUSER,DELUSER,CHANGEPWD,
  RESETPWD,RESETCOUNT,LOCKUSER,
  SAVEUSERROLE,GETUSERROLE,GETUNREVIEWED,
  LOGOUT, GETMODIFYTIME, LOGINTIMEOUT,
  SETCONFIG,GETSMS,LOGINSMS,TOKEN2
} from "@/services/api";
import { request, METHOD } from "@/utils/request";

/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function login(name, password, vercode, vercodeToken) {
  return request(LOGIN, METHOD.POST, {
    username: name,
    password: password,
    vercode: vercode,
    vercodeToken: vercodeToken,
    key: 'rsnsrsnsrsnsrsns'
  });
}
//手机验证码登录
export async function loginSms(phone, password, smsCode, smsCodeToken) {
  return request(LOGINSMS, METHOD.POST, {
    phone: phone,
    password: password,
    smsCode: smsCode,
    smsCodeToken: smsCodeToken,
    key:'rsnsrsnsrsnsrsns'
  });
}
//获取手机短信验证码
export function getSms(param) {
  return request(GETSMS, METHOD.GET, param);
}
//获取路由
export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET);
}
//修改密码
export async function changePwd(password, type, oldPassword) {
  return request(CHANGEPWD, METHOD.POST, {
    password: password,
    type: type,
    oldPassword: oldPassword,
    key:'rsnsrsnsrsnsrsns'
  });
}

/**
 * 退出登录
 */
export function logout(param) {
  return request(LOGOUT, METHOD.GET, param);
}
//企业微信扫码登录
export async function WXLogin(param) {
  return request(WXLOGIN, METHOD.GET, param);
}
//企业微信扫码绑定账号
export async function WXBinding(param) {
  return request(WXBINDING, METHOD.POST, param);
}
//查看企业微信是否绑定
export async function WXBindingCase(param) {
  return request(WXBINDINGCASE, METHOD.GET, param);
}
//企业微信解除绑定
export async function WXUnbinding(param) {
  return request(WXUNBINDING, METHOD.GET, param);
}
//用户列表
export async function list(param) {
  return request(USER, METHOD.GET, param);
}
//用户添加
export function add(param) {
  return request(ADDUSER, METHOD.POST, param);
}
//用户编辑
export function update(param) {
  return request(UPDATEUSER, METHOD.POST, param);
}
//用户删除
export function del(param) {
  return request(DELUSER, METHOD.POST, param);
}
//用户授权
export function auth(param) {
  return request(AUTHUSER, METHOD.POST, param);
}
//重置密码
export function resetPwd(param) {
  return request(RESETPWD, METHOD.POST, param);
}
//重置登陆错误次数
export function resetLoginErrCount(param) {
  return request(RESETCOUNT, METHOD.POST, param);
}
//锁定/解锁用户
export function lockUser(param) {
  return request(LOCKUSER, METHOD.POST, param);
}
//用户授权角色
export function saveRoles(param) {
  return request(SAVEUSERROLE, METHOD.POST, param);
}
//获取角色授权
export function getRoles(param) {
  return request(GETUSERROLE, METHOD.GET, param);
}
//获取素材未检测和插播未检测次数
export function getUnreviewed(param) {
  return request(GETUNREVIEWED, METHOD.GET, param);
}

export function getModifyTime(param) {
  return request(GETMODIFYTIME, METHOD.GET, param);
}

export function getExpire(param) {
  return request(LOGINTIMEOUT, METHOD.GET, param);
}

export function setConfig(param) {
  return request(SETCONFIG, METHOD.POST, param);
}
//一网通登录
export function getToken2(param) {
  return request(TOKEN2, METHOD.POST, param);
}

export default {
  login,
  logout,
  getRoutesConfig
};
